package com.casic.ops.configs;

import com.casic.ops.event.OpsPushAppListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @ClassName ops
 * @Description 异步消息, 后面用来做解耦使用
 * @Author mianbin
 * @Date 2022/6/18 16:38
 * @Version 1.0
 **/
@Configuration
@EnableAsync
public class ListenerConfig {

    //
    // 异步事件线程池
    //
    @Bean(name = "asyncExecutor")
    public Executor asyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(4);
        executor.setQueueCapacity(1000);
        executor.setThreadNamePrefix("AsynchThread-");
        executor.initialize();
        return executor;
    }

    /**
     * 加入spring容器
     */
    @Bean
    public OpsPushAppListener opsPushAppListener() {
        return new OpsPushAppListener();
    }


}
